#子路由创建使用的步骤
#1.导入APIRouter
from fastapi import APIRouter

#2使用json传参
#2.1.导入BaseModel
from pydantic import BaseModel

#2.2.设置一个类
class Student(BaseModel):
    id:int
    name:str
    msg:str|None = None
#2.实现一个子路由
api_student = APIRouter()

@api_student.post('/add')  #默认前缀+mapping http://127.0.0.1:8000/student/add?
def post_hello(student:Student):
    return student
@api_student.get('/get') #http://127.0.0.1:8000/student/get?id = 1
def get_student(id):
    return {'id':id,'name':'name'}
@api_student.get('/del')#http://127.0.0.1:8000/student/del?id = 1
def del_student(id):
    return "删除学生"
@api_student.post('/mod')#http://127.0.0.1:8000/student/mod
def mod_student(student:Student):
    return '改'


#3.由main执行外部的子路由的导入